Page({
  data: {

  },
  onLoad: function (options) {
    console.log(options.studentID)
    this.setData({
      studentID:options.studentID
    })
  },
  bindSave:function(e){
    var phone=e.detail.value.phone
    var phones=e.detail.value.phones
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (phone == null ) {
      wx.showToast({
        title: '请输入手机号！',
        icon: 'none',
        duration: 2000,
      })
      return false
    } else if(phones == null ) {
      wx.showToast({
        title: '请确认手机号！',
        icon: 'none',
        duration: 2000,
      })
      return false
    } else if(!myreg.test(phones)) {
      wx.showToast({
        title: '手机号有误！',
        icon: 'none',
        duration: 2000
      })
      return false;
    }else if(phone!=phones){
      wx.showToast({
        title: '两次手机不匹配',
        icon: 'none',
        duration: 2000
      })
      return false;
    }

    wx.cloud.callFunction({
      name:"alterphone",
      data:{
        studentID:this.data.studentID,
        phones:phones
      }
    }).then(res=>{
      wx.showToast({
        title: '修改成功',
        icon: 'loading',
        mask:true,
        duration: 2000,
        success:function(){
          setTimeout(function () {
            //要延时执行的代码
            wx.navigateBack({})
          }, 2000) //延迟时间
        }
      })
    })
  }
})